import numpy as np
import pandas as pd
from scipy import stats


def t_test(data,url):
    if url:
        data_sum = pd.read_excel(url)
        data_sum_nparray = np.array(data_sum)
        data_list = data_sum_nparray.tolist()
        data1 = [row[0] for row in data_list]
        data2 = [row[1] for row in data_list]
    else:
        data_sum_nparray = np.array(data)
        data_list = data_sum_nparray.tolist()
        data1 = [row[0] for row in data_list]
        data2 = [row[1] for row in data_list]

    stat, p = stats.levene(data1, data2)
    # return stat, p
    result = [[{'T统计量的值': stat, '最小显著性水平': p}]]
    return result


if __name__ == "__main__":
    # 读取文件
    url = 'ttest_data.xlsx'
    data = pd.read_excel('ttest_data.xlsx')

    # stat：t统计量的值
    # p：显著性水平
    array  = t_test (data,url)

    print(array)
